package com.yesep.learn.jwt.util;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {

	public static Authentication getAuthentication() throws AuthenticationException {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		return authentication;
	}

	public static String getUsername() throws AuthenticationException {
		Authentication authentication = getAuthentication();
		return authentication == null ? null : authentication.getPrincipal().toString();
	}
}
